package com.agency8x.controller;

import com.agency8x.bean.SearchParamBean;
import com.agency8x.interceptor.CheckLoginInterceptor;
import com.agency8x.model.MemberModel;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;

/**
 * 用户管理
 */
@Before(CheckLoginInterceptor.class)
public class MemberController extends Controller {
	
	// 获取和设置查询参数
	private SearchParamBean getAndSetQueryParams(){
		SearchParamBean bean=new SearchParamBean();
		bean.setWord(getPara("word", ""));
		bean.setDate1(getPara("date1", ""));
		bean.setDate2(getPara("date2", ""));
		this.setAttr("word", bean.getWord());
		this.setAttr("date1", bean.getDate1());
		this.setAttr("date2", bean.getDate2());
		return bean;
	}
	
	public void index(){
		SearchParamBean search=getAndSetQueryParams();
		setAttr("listPage", MemberModel.me.paginate(getParaToInt(0, 1), 10, search.getWord(),search.getDate1(),search.getDate2()));
		// 设置传入分页的url参数
		this.setAttr("append", search.getQueryString());
		this.render("index.html");
	}
	
	//无昵称
	public void unsubscrible(){
		SearchParamBean search=getAndSetQueryParams();
		setAttr("listPage", MemberModel.me.pagNoname(getParaToInt(0, 1), 10, search.getWord(),search.getDate1(),search.getDate2()));
		// 设置传入分页的url参数
		this.setAttr("append",search.getQueryString());
		this.render("unsubscrible.html");
	}
	
	//一级下线
	public void child1(){
		String search_word = this.getPara("word");
		String user_id = this.getPara("user_id");
		this.setAttr("user_id", user_id);
		setAttr("itemData", MemberModel.me.agenEdit(user_id));
		setAttr("listPage", MemberModel.me.pagchild1(getParaToInt(0, 1), 10,user_id, search_word));
		// 设置传入分页的url参数
		if (StrKit.notBlank(search_word) || StrKit.notBlank(user_id)) {
			this.setAttr("append", "?word=" + search_word + "&&user_id=" + user_id);
		}
		this.render("child1.html");
	}
	
	//二级下线
	public void child2(){
		String search_word = this.getPara("word");
		String user_id = this.getPara("user_id");
		this.setAttr("user_id", user_id);
		setAttr("itemData", MemberModel.me.agenEdit(user_id));
		setAttr("listPage", MemberModel.me.pagchild2(getParaToInt(0, 1), 10,user_id, search_word));
		// 设置传入分页的url参数
		if (StrKit.notBlank(search_word) || StrKit.notBlank(user_id)) {
			this.setAttr("append", "?word=" + search_word + "&&user_id=" + user_id);
		}
		this.render("child2.html");
	}
	
}
